package cz.muni.fi.pa036is.servicesimplementation;

import cz.muni.fi.pa036is.daointerface.ComplaintDAO;
import cz.muni.fi.pa036is.daointerface.MatchDAO;
import cz.muni.fi.pa036is.dto.ComplaintDetailTO;
import cz.muni.fi.pa036is.dto.ComplaintFormTO;
import cz.muni.fi.pa036is.dto.ComplaintGridTO;
import cz.muni.fi.pa036is.dtoconverters.ComplaintConverter;
import cz.muni.fi.pa036is.entity.Complaint;
import cz.muni.fi.pa036is.servicesinterface.ComplaintService;
import cz.muni.fi.pa036is.utilities.TimeService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author Shebik
 */
@Service
public class ComplaintServiceImpl implements ComplaintService {

    @Autowired
    private ComplaintDAO complaintDAO;

    @Autowired
    private MatchDAO matchDAO;

    @Override
    public void addComplaint(final ComplaintFormTO complaintFormTO) {
        final Complaint complaint =
                ComplaintConverter.convertToComplaint(complaintFormTO);
        complaint.setTimestamp(TimeService.getCurrentTimestamp());
        complaintDAO.addComplaint(complaint);
								complaintFormTO.setId(complaint.getId());
    }

    @Override
    public void deleteComplaint(final Long id) {
        complaintDAO.deleteComplaint(id);
    }

    @Override
    public ComplaintDetailTO getComplaintDetailTO(final Long id) {
        return ComplaintConverter.convertToComplaintDetailTO(
                complaintDAO.findComplaint(id));
    }
				
    @Override
    public List<ComplaintGridTO> getAllComplaints() {
        return ComplaintConverter.convertToComplaintGridTOList(
                complaintDAO.getAllComplaints());
    }

				@Override
				public List<ComplaintGridTO> getComplaintsByMatch(Long id) {
								return ComplaintConverter.convertToComplaintGridTOList(
                complaintDAO.getComplaintsByMatch(id));
				}
}
